package com.ruoyi.project.business.schedulerule.controller;

import java.util.List;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import com.ruoyi.framework.aspectj.lang.annotation.Log;
import com.ruoyi.framework.aspectj.lang.enums.BusinessType;
import com.ruoyi.project.business.schedulerule.entity.MonthScheduleRule;
import com.ruoyi.project.business.schedulerule.request.ListMonthScheduleRuleRequest;
import com.ruoyi.project.business.schedulerule.request.AddMonthScheduleRuleRequest;
import com.ruoyi.project.business.schedulerule.response.MonthScheduleRuleResponse;
import com.ruoyi.project.business.schedulerule.service.IMonthScheduleRuleService;
import com.ruoyi.framework.web.controller.BaseController;
import com.ruoyi.framework.web.model.AjaxResult;
import com.ruoyi.framework.web.page.TableDataInfo;

/**
 * 排班规则Controller
 * 
 * @author ${author}
 * @date 2024-03-06
 */
@RestController
@RequestMapping("/business/schedulerule")
public class MonthScheduleRuleController extends BaseController {
    @Autowired
    private IMonthScheduleRuleService monthScheduleRuleService;

    /**
     * 查询排班规则列表
     */
    @PreAuthorize("@ss.hasPermi('business:schedulerule:list')")
    @GetMapping("/list")
    public TableDataInfo list(ListMonthScheduleRuleRequest request) {
        startPage();
        Long tenantId = getTenantId();
        List<MonthScheduleRuleResponse> list = monthScheduleRuleService.selectMonthScheduleRuleList(request, tenantId);
        return getDataTable(list);
    }

    /**
     * 导出排班规则列表
     */
//    @PreAuthorize("@ss.hasPermi('business:schedulerule:export')")
//    @Log(title = "排班规则", businessType = BusinessType.EXPORT)
//    @GetMapping("/export")
//    public AjaxResult export(ListMonthScheduleRuleRequest request) {
//        Long tenantId = getTenantId();
//        List<MonthScheduleRuleResponse> list = monthScheduleRuleService.selectMonthScheduleRuleList(request, tenantId);
//        ExcelUtil<MonthScheduleRuleResponse> util = new ExcelUtil<>(MonthScheduleRuleResponse.class);
//        return util.exportExcel(list, "schedulerule");
//    }

    /**
     * 获取排班规则详细信息
     */
    @PreAuthorize("@ss.hasPermi('business:schedulerule:query')")
    @GetMapping(value = "/{id}")
    public AjaxResult getInfo(@PathVariable("id") Long id) {
        return AjaxResult.success(monthScheduleRuleService.selectMonthScheduleRuleById(id));
    }

    /**
     * 新增排班规则
     */
    @PreAuthorize("@ss.hasPermi('business:schedulerule:add')")
    @Log(title = "排班规则", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody AddMonthScheduleRuleRequest request) {
        Long tenantId = getTenantId();
        Long operatorId = getUserId();
        return toAjax(monthScheduleRuleService.insertMonthScheduleRule(request, operatorId, tenantId));
    }

    /**
     * 修改排班规则
     */
    @PreAuthorize("@ss.hasPermi('business:schedulerule:edit')")
    @Log(title = "排班规则", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody MonthScheduleRule monthScheduleRule) {
        Long tenantId = getTenantId();
        Long operatorId = getUserId();
        return toAjax(monthScheduleRuleService.updateMonthScheduleRule(monthScheduleRule, operatorId, tenantId));
    }

    /**
     * 删除排班规则
     */
    @PreAuthorize("@ss.hasPermi('business:schedulerule:remove')")
    @Log(title = "排班规则", businessType = BusinessType.DELETE)
	@DeleteMapping("/{ids}")
    public AjaxResult remove(@PathVariable Long[] ids) {
        Long tenantId = getTenantId();
        Long operatorId = getUserId();
        return toAjax(monthScheduleRuleService.deleteMonthScheduleRuleByIds(ids, operatorId, tenantId));
    }
}
